﻿<!DOCTYPE html>
<html>

	<head>
			<meta charset="utf-8">
			<title>我的笔记</title>
			<meta name="viewport" content="width=device-width, initial-scale=1.0">
			<meta http-equiv="x-pjax-version" content="v173">
			<link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/favico-144-precomposed.png">
			<link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/favico-114-precomposed.png">
			<link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/favico-72-precomposed.png">
			<link rel="apple-touch-icon-precomposed" href="ico/favico-57-precomposed.png">
			<link rel="shortcut icon" href="ico/favico.png">
			<link rel="shortcut icon" href="ico/favico.ico">
			<link rel="stylesheet" href="styles/icon.css"/>
			<link rel="stylesheet" href="styles/main.css"/>
			<!-- Google-Code代码高亮CSS -->
			<link rel="stylesheet" href="styles/prettify.css"/>
			<!-- Ueditor编辑器CSS -->
			<link href="styles/umeditor.min.css" type="text/css" rel="stylesheet">
			<script src="scripts/cookie_util.js" type="text/javascript"></script>
			<script src="scripts/jquery.min.js" type="text/javascript"></script>
		</head>
	<body class="animated fadeIn">

		<div style="margin:0px 60px 0px 60px">
			<header style='padding:0;margin:0px 30px 0px 30px;' class="header" >
				<div class="header-brand">
					<a data-pjax=".content-body" href="edit.html">
						<img class="brand-logo" src="images/dummy/8986f28e.stilearn-logo.png" alt="Stilearn Admin Sample Logo">
					</a>
				</div>
				<div class="header-profile">
					<div class="profile-nav">
						<span class="profile-username"></span>
						<a  class="dropdown-toggle" data-toggle="dropdown">
							<span class="fa fa-angle-down"></span>
						</a>
						<ul class="dropdown-menu animated flipInX pull-right" role="menu">
							<li><a href="Change_password.html"><i class="fa fa-user"></i> 修改密码</a></li>
							<li class="divider"></li>
							<li><a id="logout" href="log_in.html" ><i class="fa fa-sign-out"></i> 退出登录</a></li>
						</ul>
					</div>
				</div>
				<form class="form-inline" onsubmit="return false;">
					<button type="button" class="btn btn-default btn-expand-search"><i class="fa fa-search"></i></button>
					<div class="toggle-search">
						<input type="text" class="form-control" placeholder="搜索笔记" id='search_note'>
						<button type="button" class="btn btn-default btn-collapse-search"><i class="fa fa-times"></i></button>
					</div>
				</form>
				<ul class="hidden-md header-menu pull-right">
					<li>
						<a href="activity.html" target='_blank' title="笔记活动">活动</a>
					</li>
				</ul>
			</header >
			<div class="row" style='padding:0; margin:0px 0px 0px 30px;' id='center'>
				<!-- alert_background-->
				<div class="opacity_bg" style='display:none;'></div>
				<!-- alert_notebook -->
				<div id="can"></div>
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding: 0px' id='pc_part_1'>
					<!-- side-right -->
					<div class="pc_top_first">
						<div class="row clear_margin">
							<h3 class="col-md-8">全部笔记本</h3>
							<div class="row ">
								<button style="margin: 0px 25px 1px 0px;" type="button" class="btn btn-default btn_plus" id='delete_notebook' ><i class="fa fa-minus"></i></button>
								<button style="margin: 3px 0px 3px 6px;" type="button" class="btn btn-default btn_plus" id='add_notebook'><i class="fa fa-plus"></i></button>
							</div>
						</div>
					</div>
					<aside class="side-right" id='first_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list" id="notebooklist">
									</ul>
								</div>
							</div>
						</div>
					</aside>
					<div class="row clear_margin">
						<div class="col-md-4 click" id='rollback_button' title='回收站'><i class='fa fa-trash-o' style='font-size:20px;line-height:31px;'></i></div>
						<div class="col-md-4 click" id='like_button' title='收藏笔记本'><i class='fa fa-star' style='font-size:20px;line-height:31px;'></i></div>
						<div class="col-md-4 click" id='action_button' title='参加活动笔记'><i class='fa fa-users' style='font-size:20px;line-height:30px;'></i></div>
					</div>
				</div>
				<!-- 全部笔记本 -->
				<!-- 全部笔记 -->
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding:0;' id='pc_part_2'>
					<div class="pc_top_second" id='notebookId'>
						<h3>全部笔记</h3>
						<button type="button" class="btn btn-default btn-md btn_plus" id='add_note'><i class="fa fa-plus"></i></button>
					</div>
					<aside class="side-right" id='second_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list" id="notelist">
									</ul>
								</div>
							</div>
						</div>
					</aside>
				</div>
				<!-- 全部笔记 -->
				<!-- 回收站笔记 -->
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding:0;display:none;' id='pc_part_4'>
					<div class="pc_top_second">
						<h3>回收站笔记</h3>
						<button type="button" class="btn btn-default btn-md btn_plus " id="join_action">清空回收站</button>
					</div>
					<aside class="side-right" id='four_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list" id="recyclelist"></ul>
								</div>
							</div>
						</div>
					</aside>
				</div>
				<!-- 回收站笔记 -->
				<!-- 搜索笔记列表 -->
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding:0;display:none;' id='pc_part_6'>
					<div class="pc_top_second">
						<h3>搜索结果</h3>
					</div>
					<aside class="side-right" id='sixth_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list">
									</ul>
								</div>
							</div>
							<div id='more_note'>更多...</div>
						</div>
					</aside>
				</div>
				<!-- 搜索笔记列表 -->
				<!-- 收藏笔记列表 -->
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding:0;display:none;' id='pc_part_7'>
					<div class="pc_top_second">
						<h3>已收藏笔记</h3>
					</div>
					<aside class="side-right" id='seventh_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list" id="favorList">
										<!--li class="idle"><a ><i class="fa fa-file-text-o" title="online" rel="tooltip-bottom"></i> switch多分支结构<button type="button" class="btn btn-default btn-md btn_position btn_delete"><i class="fa fa-times"></i></button></a></li-->
									</ul>
								</div>
							</div>
						</div>
					</aside>
				</div>
				<!-- 收藏笔记列表 -->
				<!-- 参加活动的笔记列表 -->
				<div class="col-md-2" style='margin:5px 10px 5px 0px;padding:0;display:none;' id='pc_part_8'>
					<div class="pc_top_second">
						<h3>参加活动的笔记</h3>
					</div>
					<aside class="side-right" id='eighth_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body">
									<ul class="contacts-list">
										<!--li class="offline"><a ><i class="fa fa-file-text-o" title="online" rel="tooltip-bottom"></i> 样式用例（点击无效）</a></li-->
									</ul>
								</div>
							</div>
						</div>
					</aside>
				</div>
				<!-- 参加活动的笔记列表 -->
				<!-- 编辑笔记 -->
				<div class="col-sm-7"  id='pc_part_3' style='margin:5px 0px 0px 0px;padding:0;'>
					<!-- side-right -->
					<div class="pc_top_third">
						<div class="row">
							<div class="col-md-9">
								<h3>编辑笔记</h3>
							</div>
							<div class="col-md-3">
								<button type="button" class="btn btn-block btn-sm btn-primary" id='save_note'>保存笔记</button>
							</div>
						</div>
					</div>
					<aside class="side-right" id='third_side_right'>
						<div class="module" data-toggle="niceScroll">
							<div class="chat-contact">
								<div class="contact-body clear_margin">
									<!--- 笔记标题 --->
									<div class="row" >
										<div class="col-md-8">
											<input type="text" class="form-control" id="input_note_title" placeholder='笔记标题...'>
										</div>
									</div>
									<!--- 笔记标题 --->
									<div class="row">
										<div class="col-sm-12">
											<!--- 输入框 --->
											<script type="text/plain" id="myEditor" style="width:100%;height:400px;">
											</script>
											<!--- 输入框 --->
										</div>
									</div>
								</div>
							</div>
						</div>
					</aside>
				</div>
				<!-- 编辑笔记 -->
				<!-- 预览笔记 -->
				<div class="col-sm-7" id='pc_part_5' style='display:block;' >

					<aside style="background: none" class="side-right" id='fifth_side_right'>
						<div class="jumbotron">
							<div id="helloworld"></div>
							<p><a class="btn btn-primary btn-lg" href="#" role="button" id="add_notebook2">新建笔记本</a></p>
						</div>

					</aside>
				</div>
				<!-- 预览笔记 -->
			</div>
			<footer style='padding:0;margin:0px 30px 0px 30px;' >
				<p>&copy; 2023 Stilearning</p>
				<div style='position:absolute;top:5PX;height:30px;right:20px;line-height:26px;border:1px solid #0E7D76;display:none;background:#fff'>
					<strong style='color:#0E7D76;margin:0 10px;'></strong>
				</div>
			</footer>
		</div>

		<script type="text/javascript" src="scripts/jquery.min.js"></script>

		<!-- Bootstrap框架JS -->
		<script src="scripts/bootstrap.min.js"></script>
		<script src="scripts/js-prototype.js"></script>
		<script src="scripts/theme-setup.js"></script>
		<!-- Google-Code代码高亮JS -->
		<script class="re-execute" src="scripts/run_prettify.js"></script>
		<!-- Ueditor编辑器JS -->
		<script type="text/javascript" charset="utf-8" src="scripts/ue/umeditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="scripts/ue/umeditor.min.js"></script>
		<script type="text/javascript" src="scripts/ue/lang/zh-cn.js"></script>

		<script type="text/javascript">


			var uid = getCookie("userId"); //查询客户的cookie，name是userId
			if(uid==null){ // 如果userId不存在，跳转到登录页面
				window.location.href="log_in.html";
			}else{
				// 如果存在，发送查询Notebook的请求，后台SSM流程
				loadNotebookByUser();//加载笔记本
				console.log("加载笔记本");
			}
			clear_all_selected();

			// 预加载=============================================
			$(document).ready(function () {
				//欢迎页面
				$.ajax({
					url:"/cloudNote_war_exploded/getUserName",
					type:"POST",
					data:{uid:uid,},
					success:function (res){
						var dataContainer = $("#helloworld");
						var currentDate = new Date();
						var currentYear = currentDate.getFullYear();
						var currentMonth = currentDate.getMonth() + 1;
						var currentDay = currentDate.getDate();
						var currentHour = currentDate.getHours();
						var time = '';
						dataContainer.empty();
						if(currentHour<11){
							time = "上午好";
						}
						else if(currentHour>=11 && currentHour<13){
							time = "中午好";
						}
						else{
							time = "下午好";
						}
						var lis='';
						// 创建新的元素来展示每个数据项
						lis +="<h1>" + time + "，"+res+"</h1><br>";
						lis +="<h3>今天是"+currentYear+"年"+currentMonth+"月"+currentDay+"日"+"</h3>";
						lis +="<br><p>想要记录一些生活小碎片吗？</p><br>"
						// 将新元素添加到容器中
						$(dataContainer).append(lis);
					},
					error() {
						console.log("失败");
					}
				})


				var notebookId = null;

				//笔记本双击事件（重命名）
				$("#notebooklist").on("dblclick","li",function () {
					// 处理双击事件
					$(".opacity_bg").css("display","block");
					console.log("双击成功")
					$("#can").load("alert/alert_rename.html");
				});

				//重命名事件
				$("#can").on("click", "#rename_notebook_btn", function () {
					var new_name = $('#input_notebook_rename').val();
					$.ajax({
						url:"/cloudNote_war_exploded/renameNoteBook",
						type:"post",
						data:{note_rename:new_name,bookid:currentNoteBookId},
						success:function (){
							loadNotebookByUser(uid);
							alert("重命名成功");
						},
						error() {
							alert("重命名失败");
						}
					});
				})

				// 添加笔记本按钮响应事件
				$("#add_notebook").click(function(){
					$(".opacity_bg").css("display","block");
					$("#can").load("alert/alert_notebook.html");
				});
				$("#add_notebook2").click(function(){
					$(".opacity_bg").css("display","block");
					$("#can").load("alert/alert_notebook.html");
				});

				// 删除笔记本按钮响应事件
				$("#delete_notebook").click(function(){
					const $a = $("#notebooklist li .checked");
					// 当 .length 属性是0时，表示没有选中记事本；如果是1，表示选中一个记事本
					if ($a.length == 0) {
						alert("请先选中记事本！");
						return;
					}
					$(".opacity_bg").css("display","block");
					$("#can").load("alert/alert_delete_notebook.html");
				});

				// 添加笔记本事件
				$("#can").on("click","#add_notebook_button",function(){

					let userid = sessionStorage.getItem("userId");
					let bookname=$("#input_notebook").val();
					$.ajax({
						url:"/cloudNote_war_exploded/addNoteBook",
						type:"post",
						data:{"uid":userid,"bookname":bookname},
						success:function (res){
							if(res.code==7){
								alert("创建笔记本成功: "+ bookname); //弹出提示框
								$("#notebooklist").empty();
								loadNotebookByUser(); // 加载用户对应的笔记本
							}
						},
						error() {
							alert("创建笔记本失败");
						}
					});
				});

				// 删除笔记本事件
				$("#can").on("click", "#delete_notebook_button", function () {
					let notebookId = $("#notebooklist li .checked").parent().attr("data-id");
					let userid = sessionStorage.getItem("userId");

					$.ajax({
						url: '/cloudNote_war_exploded/deleteNotebook', // 请求的url
						type: 'POST', // 请求方式，GET或POST
						data: { // 发送服务器的数据String notebookid, String noteName, String userid
							id: notebookId
						},
						success: function (data) {

							loadNotebookByUser(userid);
							getNoteList(notebookId);
							alert("删除笔记本成功");
						},
						error: function () { // statusCode是2xx 或 304 以外的值时，执行该函数
							alert("删除笔记本失败");
						}

					});

				});

				// 笔记本被点击事件(查询笔记本对应笔记列表)
				$("#notebooklist").on("click","li",function () {
					$("#notebooklist li a").removeClass("checked");
					$(this).find("a").addClass("checked");
					var notebookId = $(this).attr("data-id");
					currentNoteBookId = notebookId;
					console.log("notebookId:",notebookId);
					open_notelist(true);
					getNoteList(notebookId);
				});

				// 添加笔记按钮响应事件
				$("#add_note").click(function () {
					// 选择选中记事本的元素
					const $a = $("#notebooklist li .checked");
					// 当 .length 属性是0时，表示没有选中记事本；如果是1，表示选中一个记事本
					if ($a.length == 0) {
						alert("请先选中记事本！");
						return;
					}

					$('.opacity_bg').show(); // 遮罩层
					// 发送ajax请求，将返回的html代码显示到id是can的标签中
					$("#can").load("alert/alert_note.html");
				});

				// 添加笔记事件
				$("#can").on("click", "#create_note_btn", function () {
					let notebookId = $("#notebooklist li .checked").parent().attr("data-id");
					const title = $("#input_note").val();
					let userid = sessionStorage.getItem("userId");
					if (title === "") {
						alert("请输入标题！");
						return;
					}

					$.ajax({
						url: '/cloudNote_war_exploded/addNote', // 请求的url
						type: 'POST', // 请求方式，GET或POST
						data: { // 发送服务器的数据String notebookid, String noteName, String userid
							notebookid: notebookId,
							noteName: title,
							userid: userid,
						},
						success: function (data) {
							console.log(data);
							if (data.status === 0) {


							} else {
								alert(data.msg);
							}
							getNoteList(notebookId);
						},
						error: function (xhr, textStatus) { // statusCode是2xx 或 304 以外的值时，执行该函数
							console.log('错误');
							console.log(xhr);
							console.log(textStatus);
						}

					});

				});

				// 点击笔记后面的按钮，显示相关操作
				$("#notelist").on("click",".btn_slide_down",function () {
					// $(this).parent().parent().find(".note_menu").show()
					$(this).parents("li").find(".note_menu").slideDown() //有动画效果的伸展菜单
				})

				// 鼠标移出笔记相关操作区域，就隐藏
				$("#notelist").on("mouseleave",".note_menu",function () {
					// $(this).hide()
					$(this).slideUp()  //有动画效果的收回菜单
				})

				//点击移动笔记按钮
				$("#notelist").on("click",".btn_move",function () {

					// 弹出确认收藏对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_move.html");
					getNoteBookList("#MoveSelect");

				});

				//移动笔记事件
				$("#can").on("click","#move_button",function () {
					let notebookid = $("#MoveSelect").val();
					console.log("需要看到的值:"+notebookid);
					const $li = $("#notelist li .checked").parents("li");
					const id = $li.attr("data-id");
					console.log("笔记id="+id);
					$.ajax({
						url:'/cloudNote_war_exploded/moveNote',//请求的url
						method:'post',
						data:{
							noteid:id,
							target: notebookid,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							getNoteList(currentNoteBookId);
						},
						error:function(){
							alert("移动笔记失败");
						}
					});

				})

				// 移入回收站按钮
				$("#notelist").on("click",".btn_delete",function () {
					// 弹出确认删除对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_delete_note.html")
				});

				// 回收站彻底删除按钮
				$("#recyclelist").on("click","#delete_completely",function () {
					// 弹出确认删除对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_delete_rollback.html")
				});

				// 回收站笔记被点击事件
				$("#recyclelist").on("click","li",function(){
					$("#recyclelist li a").removeClass("checked");
					$(this).find("a").addClass("checked");
				})

				// 彻底删除笔记事件
				$("#can").on("click","#delete_completely",function () {

					// 查找祖先元素，并且是 li 标签的祖先
					const $li = $("#recyclelist li .checked").parents("li");
					const id = $li.attr("data-id");
					console.log("id:",id);

					$.ajax({
						url:'/cloudNote_war_exploded/deleteNote',//请求的url
						type:'POST',
						data:{
							id:id,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							loadRecycledList();
						},
						error:function(){
							alert("彻底删除笔记失败");
						}
					});
				});

				// 回收站恢复按钮
				$("#recyclelist").on("click","#replay_button",function () {
					// 弹出确认删除对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_replay.html")
					getNoteBookList("#replaySelect");
				});

				// 回收站恢复事件
				$("#can").on("click","#replay_button",function () {

					let notebookid = $("#replaySelect").val();
					console.log("notebookid="+notebookid);
					const $li = $("#recyclelist li .checked").parents("li");
					const id = $li.attr("data-id");

					$.ajax({
						url:'/cloudNote_war_exploded/moveNote',//请求的url
						method:'post',
						data:{
							noteid:id,
							target: notebookid,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							loadRecycledList();
						},
						error:function(){
							alert("恢复笔记失败");
						}
					});
				});

				// 一键清空回收站按钮
				$("#join_action").click(function () {
					$('.opacity_bg').show(); // 遮罩层
					// 发送ajax请求，将返回的html代码显示到id是can的标签中
					$("#can").load("alert/alert_clear_dustbin.html");
				});


				// 清空回收站事件
				$("#can").on("click","#clear_dustbin_btn",function () {
					$.ajax({
						url:'/cloudNote_war_exploded/clearDustbin',//请求的url
						type:'POST',
						data:{
							uid:uid,
						},
						success:function(data){
							loadRecycledList();
						},
						error:function(){
							alert("清空回收站失败");
						}
					});
				});

				// 移入回收站事件
				$("#can").on("click","#delete_note_btn",function () {

					// 查找祖先元素，并且是 li 标签的祖先
					const $li = $("#notelist li .checked").parents("li")
					const id = $li.attr("data-id")
					console.log("id:",id)

					$.ajax({
						url:'/cloudNote_war_exploded/recycleNote',//请求的url
						type:'POST',
						data:{
							id:id,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							getNoteList(currentNoteBookId);
						},
						error:function(){
							alert("删除笔记失败");
						}
					});
				});

				// 关闭模态框
				$("#can").on("click",".close,.cancle,.sure,.move,.rename",function(){ // 关闭笔记本弹出锁屏对话框
					$(".opacity_bg").css("display","none");
					$("#can").html("");
				});

				//点击收藏笔记按钮
				$("#notelist").on("click",".btn_favorite",function () {
					// 弹出确认收藏对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_like.html")
				});

				//点击收藏笔记确认对话框按钮
				$("#can").on("click","#favor_note_btn",function () {

					// 查找祖先元素，并且是 li 标签的祖先
					const $li = $("#notelist li .checked").parents("li")
					const id = $li.attr("data-id")
					console.log("id:",id)

					$.ajax({
						url:'/cloudNote_war_exploded/favorNote',//请求的url
						type:'POST',
						data:{
							id:id,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							getNoteList(currentNoteBookId);
						},
						error:function(){
							console.log("error")
						}
					});
				});

				//点击取消收藏笔记按钮
				$("#favorList").on("click","#btn_delete_favor",function () {
					// 弹出确认取消收藏对话框
					$('.opacity_bg').show();// 遮罩层
					// 发送ajax请求，将返回的html代码显示到  id 是 can的标签中
					$("#can").load("alert/alert_delete_like.html")
				});

				//点击取消收藏笔记确认对话框按钮
				$("#can").on("click","#delete_favor_btn",function () {

					// 查找祖先元素，并且是 li 标签的祖先
					const $li = $("#favorList li .checked").parents("li")
					const id = $li.attr("data-id")
					console.log("id:",id)

					$.ajax({
						url:'/cloudNote_war_exploded/deletefavorNote',//请求的url
						type:'POST',
						data:{
							id:id,
						},
						success:function(data){
							console.log(data);

							if(data.status == 0){
								$li.remove();

							}
							loadFavorList();
						},
						error:function(){
							console.log("error")
						}
					});
				});

				// 收藏笔记被点击事件
				$("#favorList").on("click","li",function(){
					$("#favorList li a").removeClass("checked");
					$(this).find("a").addClass("checked");
					var noteId = $(this).attr("data-id");
					currentNoteId = noteId;

					getNote(noteId);
				})

				// 笔记被点击事件
				$("#notelist").on("click","li",function(){
					$("#notelist li a").removeClass("checked");
					$(this).find("a").addClass("checked");
					show('editor');
					var noteId = $(this).attr("data-id");
					currentNoteId = noteId;
					console.log("noteId:",noteId);
					getNote(noteId);
				})

				// 回收站展开按钮被点击事件
				$("#rollback_button").click(function (){
					show('recyclelist');
					loadRecycledList();

				});

				// 收藏列表展开按钮被点击事件
				$("#like_button").click(function (){
					show('favorlist');
					loadFavorList();
				});

				// 活动笔记展开按钮被点击事件
				$("#action_button").click(function (){
					show('sharelist');
				});

				// 笔记保存按钮点击事件
				$("#save_note").click(function (){
					var inputTitle = document.getElementById('input_note_title');
					var title = inputTitle.value;
					var content = um.getContent();
					console.log(title);
					console.log(content);
					$.ajax({
						url:'/cloudNote_war_exploded/save_note/',//请求的url
						data:{
							noteId:currentNoteId,
							note_title:title,
							note_body:content
						},
						type:'get', //请求方式，GET或POST
						success:function(res){
							if(res) {
								console.log(res);
								alert("保存成功");
								getNoteList(currentNoteBookId);
							}
							else{
								alert("保存出错");
							}
						},
						error:function(){console.log('错误！！');}
					})
				})

			});

			// 用于四个侧栏和编辑器的显示
			let ifeditor = false;let ifdustbin=false;let ifnotelist=false;let iffavor=false;let ifshare=false;
			function show(op) {
				if(op==='editor') {
					$("#pc_part_3").css("display","block");ifeditor = true;
				}
				if(ifeditor) {
					$("#pc_part_5").css("display","none");
					if(op==='notelist') {clear_all_4();}
					if(op==='recyclelist') {
						clear_all_4();
						if(!ifdustbin) {$("#rollback_button").css("background","#8d5e5b");$("#pc_part_4").css("display","block");ifdustbin = true;}
						else {$("#rollback_button").css("background","");$("#pc_part_4").css("display","none");$("#pc_part_2").css("display","block");ifdustbin = false;}
					}
					if(op==='favorlist') {
						clear_all_4();
						if(!iffavor) {$("#like_button").css("background","#8d5e5b");$("#pc_part_7").css("display","block");iffavor = true;}
						else {$("#like_button").css("background","");$("#pc_part_7").css("display","none");$("#pc_part_2").css("display","block");iffavor = false;}
					}
					if(op==='sharelist') {
						clear_all_4();
						if(!ifshare) {$("#action_button").css("background","#8d5e5b");$("#pc_part_8").css("display","block");ifshare = true;}
						else {$("#action_button").css("background","");$("#pc_part_8").css("display","none");$("#pc_part_2").css("display","block");ifshare = false;}
					}
				}
				else {
					$("#pc_part_5").css("display","block");
					if(op==='notelist') {clear_all_4();}
					if(op==='recyclelist') {
						clear_all_4();
						if(!ifdustbin) {$("#rollback_button").css("background","#8d5e5b");$("#pc_part_4").css("display","block");ifdustbin = true;}
						else {$("#rollback_button").css("background","");$("#pc_part_4").css("display","none");ifdustbin = false;}
					}
					if(op==='favorlist') {
						clear_all_4();
						if(!iffavor) {$("#like_button").css("background","#8d5e5b");$("#pc_part_7").css("display","block");iffavor = true;}
						else {$("#like_button").css("background","");$("#pc_part_7").css("display","none");iffavor = false;}
					}
					if(op==='sharelist') {
						clear_all_4();
						if(!ifshare) {$("#action_button").css("background","#8d5e5b");$("#pc_part_8").css("display","block");ifshare = true;}
						else {$("#action_button").css("background","");$("#pc_part_8").css("display","none");ifshare = false;}
					}
				}

				set_height();
				let width=$('#third_side_right').width()-35;
				$('.edui-container,.edui-editor-body').width(width);
				$('#myEditor').width(width-20);
			}

			function clear_all_4() {
				$("#pc_part_4").css("display","none");
				$("#rollback_button").css("background","");
				$("#pc_part_7").css("display","none");
				$("#like_button").css("background","");
				$("#pc_part_8").css("display","none");
				$("#action_button").css("background","");
				$("#pc_part_2").css("display","none");
			}

			// 取消所有选中
			function clear_all_selected() {
				$("#pc_part_4").css("display","none");
				$("#rollback_button").css("background","");
				$("#pc_part_7").css("display","none");
				$("#like_button").css("background","");
				$("#pc_part_8").css("display","none");
				$("#action_button").css("background","");
				$("#pc_part_2").css("display","none");
				$("#pc_part_3").css("display","none");
			}

			function open_notelist(op) {
				if(op) {
					clear_all_selected();
					$("#pc_part_2").css("display","block");
				}
				else {
					$("#pc_part_2").css("display","none");
				}
			}

			// 根据笔记本 id 查询所有笔记
			function getNoteList(notebookId) {
				$("#notelist").empty();
				$.ajax({
					url:'/cloudNote_war_exploded/getNoteList/'+notebookId,//请求的url
					type:'get', //请求方式，GET或POST
					success:function(data){ //statusCode是2xx 或 304时，执行该函数
						console.log(data);


						var lis="";
						for ( let item of data.data){
							lis += "<li class=\"online\" data-id='"+item.cn_note_id+"'>";
							lis+="<a>";
							lis+="<i class=\"fa fa-file-text-o\" title=\"online\" rel=\"tooltip-bottom\"></i> "+item.cn_note_title+"<button type=\"button\" class=\"btn btn-default btn-md btn_position btn_slide_down\"><i class=\"fa fa-chevron-down\"></i></button>"
							lis+="</a>";
							lis+="<div class=\"note_menu\" tabindex='-1'>";
							lis+="<dl>";
							lis+="<dt><button type=\"button\" class=\"btn btn-default btn-md btn_move\" title='移动至...'><i class=\"fa fa-random\"></i></button></dt>";
							lis+="<dt><button type=\"button\" class=\"btn btn-default btn-md btn_share\" title='分享'><i class=\"fa fa-sitemap\"></i></button></dt>";
							lis+="<dt><button type=\"button\" class=\"btn btn-default btn-md btn_delete\" title='删除'><i class=\"fa fa-times\"></i></button></dt>";
							lis+="<dt><button type=\"button\" class=\"btn btn-default btn-md btn_favorite\" style=\"width: 23px; height: 23px; padding: 2px;margin-left: 8px\" title='收藏'><i class=\"fa fa-heart\"></i></button></dt>";//修复了button尺寸问题
							lis+="</dl>";
							lis+="</div>";
							lis+="</li>";
						}
						$("#notelist").append(lis);

					},
					error:function(xhr,textStatus){
						console.log('错误')
						console.log(xhr)
						console.log(textStatus)
					}
				});
			}

			// 根据笔记id查询笔记标题和内容
			function  getNote(noteId){
				show('editor');
				$.ajax({
					url:'/cloudNote_war_exploded/getNote/'+noteId,//请求的url
					type:'get', //请求方式，GET或POST
					success:function(res){
						// 将笔记显示到ui里
						console.log(res.data);
						for(let item of res.data){
							console.log(item.cn_note_title);
							console.log(item.cn_note_body);
							var inputTitle = document.getElementById('input_note_title');
							inputTitle.value = item.cn_note_title;
							um.ready(function () {
								um.setContent("");
								if(item.cn_note_body) {
									um.setContent(item.cn_note_body);
								}
							});
						}

					},
					error:function(){console.log('错误！！');}
				})
			}

			// 根据用户 id 加载笔记本列表
			function loadNotebookByUser(){
				$.ajax({
					url:"/cloudNote_war_exploded/getNotebookByuserid",
					data:{"uid":uid},
					type:"get",
					success:function (res){
						$("#notebooklist").empty();
						var lis="";
						for(let item of res.data){
							lis+= '<li class="online" data-id="'+item.cn_notebook_id+'"><a><i class="fa fa-book" title="online" rel="tooltip-bottom"></i>'+item.cn_notebook_name+'</a></li>'
						}
						$("#notebooklist").append(lis);
					},
					error:function (){
						alert("无法加载笔记本列表");
					}
				});
			}

			// 一个通用的获取笔记本的函数, 传入的是容器的id
			function getNoteBookList(container){
				$.ajax({
					url:"/cloudNote_war_exploded/getNotebookByuserid",
					data:{"uid":uid},
					type:"get",
					success:function (res){
						$(container).empty();
						var lis="";
						for(let item of res.data) {
							lis += "<option value=\""+ item.cn_notebook_id +"\">"+ item.cn_notebook_name +"</option>";
						}
						$(container).append(lis);
						console.log(lis);
					},
					error:function (){
						alert("无法加载笔记本列表");
					}
				});
			}

			function loadRecycledList() {
				$("#recyclelist").empty();
				$.ajax({
					url:"/cloudNote_war_exploded/getRecycledNotes",
					data:{"uid":uid},
					type:"post",
					success:function (res){
						var lis="";
						for(let item of res.data){
							lis += "<li data-id='"+item.cn_note_id+"' class=\"disable\"><a><i class=\"fa fa-file-text-o\" title=\"online\" rel=\"tooltip-bottom\"></i>";
							lis += item.cn_note_title;
							lis += "<button id='delete_completely' type=\"button\" class=\"btn btn-default btn-md btn_position btn_delete\"><i class=\"fa fa-times\"></i></button><button id='replay_button' type=\"button\" class=\"btn btn-default btn-md btn_position_2 btn_replay\"><i class=\"fa fa-reply\"></i></button></a></li>";
						}
						$("#recyclelist").append(lis);
					},
					error:function (){
						alert("无法加载回收站列表");
					}
				});
			}

			//加载收藏笔记列表
			function loadFavorList(){
				var uid = getCookie("userId");
				$("#favorList").empty();
				$.ajax({
					url:"/cloudNote_war_exploded/getFavorNotes",
					data:{uid:uid},
					type:"post",
					success:function (res){
						console.log(res);
						var lis="";
						for ( let item of res.data) {
							lis += "<li class=\"idle\" data-id='"+item.cn_note_id+"'><a ><i class=\"fa fa-file-text-o\" title=\"online\" rel=\"tooltip-bottom\"></i>"
							lis += item.cn_note_title;
							lis += "<button type=\"button\" class=\"btn btn-default btn-md btn_position btn_delete\" id='btn_delete_favor'><i class=\"fa fa-times\"></i></button></a></li>";
						}
						$("#favorList").append(lis);
					},
					error:function (){
						alert("无法加载收藏列表");
					}
				});
			}

			//重命名笔记本
			function reNameNotebook(notebookId){

			}

			//加载DOM之后处理页面高度
			function get_dom(e){
				return document.getElementById(e);
			}
			function set_height(){
				var pc_height=window.innerHeight;
				pc_height=pc_height-132;
				get_dom('first_side_right').style.height=(pc_height-31)+'px';
				get_dom('second_side_right').style.height=pc_height+'px';
				get_dom('four_side_right').style.height=pc_height+'px';
				get_dom('sixth_side_right').style.height=pc_height+'px';
				get_dom('seventh_side_right').style.height=pc_height+'px';
				get_dom('eighth_side_right').style.height=pc_height+'px';
				get_dom('third_side_right').style.height=(pc_height-15)+'px';
				get_dom('fifth_side_right').style.height=(pc_height-15)+'px';
			}
			function myEditorWidth(){
				var dom=get_dom('third_side_right');
				var style=dom.currentStyle||window.getComputedStyle(dom, null);
				get_dom('myEditor').style.width=style.width;
			}
			set_height();
			//改变窗口大小时调整页面尺寸
			window.onresize=function(){
				set_height();
				var width=$('#third_side_right').width()-35;
				$('.edui-container,.edui-editor-body').width(width);
				$('#myEditor').width(width-20);
			};
		</script>
		<script type="text/javascript">
			//重写JS原生alert函数
			window.alert=function(e){
				$('#can').load('./alert/alert_error.html',function(){
					$('#error_info').text(' '+e);
					$('.opacity_bg').show();
				});
			}
			//实例化Ueditor编辑器
			var um = UM.getEditor('myEditor');

			//创建一个全局变量存储当前的笔记ID（悲...）
			let currentNoteId='';
			let currentNoteBookId='';
			let Movenotebookid='';
		</script>

	</body>
</html>